package com.bianmin.Data;
import lombok.Data;

@Data
public class Result <T>  {

    private int code;
    private String msg;
    private T data;

    public Result(ResultCode rc , T value) {
        this.code = rc.code;
        this.msg = rc.msg;
        this.data = value;
    }

    public Result() {

    }

    /*请求成功的数据*/
    public static <T> Result<T> success(T value) {
        Result<T> r = new Result<>();
        r.code = ResultCode.RC200.code;
        r.msg = ResultCode.RC200.msg;
        r.data = value;
        return r;
    }

    public static <T> Result<T> error(ResultCode rc) {
        Result<T> r = new Result<>();
        r.code = rc.code;
        r.msg = rc.msg;
        return r;
    }

    public static <T> Result<T> customError(int code , String msg) {
        Result<T> r = new Result<>();
        r.code = code;
        r.msg = msg;
        return r;
    }
}